﻿using ZilLion.Core.ConfigManager.Manager;

namespace ZilLion.TaskManager.Entity.Config
{
    public class TaskManagerGlobalSetting
    {
        private static volatile TaskManagerGlobalSetting _instance;
        private static readonly object Lock = new object();

        private TaskManagerGlobalSetting()
        {
        }

        /// <summary>
        ///     管理中控的host
        /// </summary>
        public string ManagerServiceHost { get; private set; }

        public static TaskManagerGlobalSetting GetInstance()
        {
            if (_instance == null)
                lock (Lock)
                {
                    if (_instance == null)
                    {
                        _instance = new TaskManagerGlobalSetting();
                        //初始化 ManagerServiceHost
                        var workstationConfig = ZilLionConfigurationManager
                            .GetConfigInstance<TaskManagerWorkStationConfig>();
                        if (workstationConfig != null && workstationConfig.PipeServiceHost.IsNotNullOrEmpty())
                            _instance.ManagerServiceHost =
                                workstationConfig.PipeServiceHost.ReplaceLast("/", string.Empty);
                        else
                            _instance.ManagerServiceHost =
                                $"http://127.0.0.1:12252";

                    }
                }
            return _instance;
        }
    }
}